package com.example.camera2demo.util;

import android.hardware.camera2.CameraCharacteristics;
import android.util.Log;

public class CameraUtil {
    private static final String TAG = "CameraUtil";

    /**
     * 硬件是否支持Camera2
     * LEVEL_LEGACY: 向后兼容模式, 如果是此等级, 基本没有额外功能, HAL层大概率就是HAL1(我遇到过的都是)
     * LEVEL_LIMITED: 有最基本的功能, 还支持一些额外的高级功能, 这些高级功能是LEVEL_FULL的子集
     * LEVEL_FULL: 支持对每一帧数据进行控制,还支持高速率的图片拍摄
     * LEVEL_3: 支持YUV后处理和Raw格式图片拍摄, 还支持额外的输出流配置
     * LEVEL_EXTERNAL: API28中加入的, 应该是外接的摄像头, 功能和LIMITED类似
     * <p>
     * 各个等级从支持的功能多少排序为: LEGACY < LIMITED < FULL < LEVEL_3
     * <p>
     * CameraCharacteristics  可通过 CameraManager.getCameraCharacteristics() 获取
     */
    public static int isHardwareSupported(CameraCharacteristics characteristics) {
        Integer deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
        if (deviceLevel == null) {
            Log.e(TAG, "can not get INFO_SUPPORTED_HARDWARE_LEVEL");
            return -1;
        }
        switch (deviceLevel) {
            case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
                Log.w(TAG, "hardware supported level:LEVEL_FULL");
                break;
            case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY:
                Log.w(TAG, "hardware supported level:LEVEL_LEGACY");
                break;
            case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3:
                Log.w(TAG, "hardware supported level:LEVEL_3");
                break;
            case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
                Log.w(TAG, "hardware supported level:LEVEL_LIMITED");
                break;
        }
        return deviceLevel;
    }
}
